home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / s / procalctableimport.pprx < prev    next >
Text File  |  1993-02-19  |  6KB  |  252 lines

  1. /*
  2. @BProCalcTableImport  @P@ICopyright Gold Disk Inc., January, 1993
  3.  
  4. This Genie will import a table of data from Professional Calc. You must have ProCalc running first and a box on the page for which the data is destined.
  5. */
  6. numeric digits 8
  7. cr  = '0a'x
  8. options results
  9.  
  10. address command
  11. call SafeEndEdit.rexx()
  12. units = ppm_GetUnits()
  13. if units = 3 then
  14.     call ppm_SetUnits(1)
  15. call ppm_AutoUpdate(0)
  16.  
  17. signal on halt
  18. signal on break_c
  19. signal on break_e
  20. signal on break_d
  21.  
  22. if ~show(p, "PCALC") then exit_msg("Please start Professional Calc and select a range before running this Genie.")
  23.  
  24. box = ppm_ClickOnBox("Click on box in which to import table..")
  25. if box = 0 then exit_msg()
  26.  
  27. /*  extract box attributes  */
  28. boxsize = ppm_GetBoxSize(box)
  29. boxposition = ppm_GetBoxPosition(box)
  30.  
  31. if ppm_Inform(2, "Delete box?",) = 1 then call ppm_DeleteBox(box)
  32.  
  33. /* tell user to start up ProCalc    */
  34. call ppm_Inform(1, "Select Range in ProCalc",)
  35. call ppm_ShowStatus("Extracting range from ProCalc")
  36.  
  37.  
  38. /* switch to ProCalc and start processing   */
  39. address "PCALC"
  40. ActivateWindow
  41. DrawMessage "Please enter Range"
  42.  
  43. 'Suppress'
  44. 'LockGUI'
  45.  
  46. /*  get range selected by user  */
  47. 'Current'
  48. range = upper(result)
  49.  
  50. if range     = '' then exit_msg("No range selected")
  51. colon_pos    = pos(':', range)
  52. if colon_pos = 0 then exit_msg("No range selected")
  53.  
  54. /*  extract the start cell and the end cell */
  55. start_cell  = substr(range, 1, colon_pos - 1)
  56. end_cell    = substr(range, colon_pos + 1)
  57. if end_cell = '' | start_cell = '' then exit_msg("Invalid Range")
  58.  
  59. /*  make sure that we go from top left to bottom right  */
  60. if start_cell > end_cell then
  61. do
  62.     temp        = start_cell
  63.     start_cell  = end_cell
  64.     end_cell    = temp
  65. end
  66.  
  67. /*  change cell coordinates to numberic values  */
  68. start_row   = cell_to_row( start_cell )
  69. end_row     = cell_to_row( end_cell )
  70. start_col   = cell_to_col( start_cell )
  71. end_col     = cell_to_col( end_cell )
  72.  
  73.  
  74. /*  calculate size of matrix    */
  75. matrix.size = start_row * start_col
  76.  
  77. start_cell  = start_cell || ':'
  78. save_start  = start_cell
  79.  
  80. 'Position' start_cell
  81.  
  82. do row = start_row to end_row
  83.  
  84.     do col = start_col to end_col
  85.  
  86.         'IsValue'
  87.  
  88.         if result then
  89.         do
  90.             'GetValue'
  91.             matrix.row.col  = result
  92.         end
  93.         else
  94.         do
  95.             'GetLabel'
  96.             matrix.row.col  = result
  97.         end
  98.  
  99.         'Cursor' 'Right'
  100.  
  101.     end
  102.  
  103.     'Position' start_cell
  104.     'Cursor' 'Down'
  105.     'Current'
  106.     start_cell = result
  107.  
  108. end
  109.  
  110. 'SelectRange' range
  111.  
  112. /*  calculate the dimensions of the new boxes   */
  113. boxwidth    = word(boxsize, 1 ) / (end_col - start_col + 1 )
  114. boxheight   = word(boxsize, 2 ) / (end_row - start_row + 1 )
  115. boxleft     = word(boxposition, 1 )
  116. boxtop      = word(boxposition, 2 )
  117. boxright    = word(boxsize, 1) + boxleft
  118. boxbottom   = word(boxsize, 2) + boxtop
  119.  
  120. 'UnLockGUI'
  121. 'UnSuppress'
  122.  
  123. call ppm_AutoUpdate(0)
  124.  
  125. bleft   = boxleft
  126. btop    = boxtop
  127.  
  128. selection   = "Right Justify Numbers"cr"Make Grid Lines"cr"Create Link"
  129. selection   = upper(ppm_SelectFromList("Select Options", 30, 5, 1, selection))
  130. if pos(GRID, selection) ~= 0 then grid = 1
  131. else grid       = 0
  132. if pos(LINK, selection) ~= 0 then link = 1
  133. else link       = 0
  134. if pos(RIGHT, selection) ~= 0 then right = 1
  135. else right  = 0
  136.  
  137. prefix  = "PCALC"
  138.  
  139. if link then
  140. do
  141.  
  142.     filename = ppm_GetFileName("Save Link Data", "", "PCalcLink.data")
  143.     if filename = '' then exit_msg()
  144.  
  145.     if ~open(file, filename, "w") then call exit_msg("Unable to open file")
  146.  
  147.     call writeln(file, range)
  148.     call writeln(file, save_start)
  149.     call writeln(file, start_row)
  150.     call writeln(file, end_row)
  151.     call writeln(file, start_col)
  152.     call writeln(file, end_col)
  153.     call close(file)
  154.     prefix  = fcomponent(filename)
  155.  
  156. end
  157.  
  158. call ppm_SetSize(12)
  159.  
  160. do row = start_row to end_row
  161.  
  162.     do col = start_col to end_col
  163.  
  164.         box = ppm_CreateBox(bleft, btop, boxwidth, boxheight, 0,prefix" "col"-"row)
  165.         bleft   = bleft + boxwidth
  166.         call ppm_SetBoxMargins(box, .1, .1, .1, .1)
  167.  
  168.         if grid then
  169.         do
  170.             call ppm_SetBoxFrame(box, 1)
  171.             call ppm_SetBoxFrameData(box, "black", "black", .5, 1, 0)
  172.         end
  173.  
  174.                 if matrix.row.col = "" then matrix.row.col = " "
  175.  
  176.         if right & datatype(matrix.row.col) = 'NUM' then
  177.             call ppm_TextIntoBox(box, "\jr"matrix.row.col)
  178.         else
  179.             call ppm_TextIntoBox(box, "\jl"matrix.row.col)
  180.     end
  181.  
  182.     bleft   = boxleft
  183.     btop    = btop  + boxheight
  184.  
  185. end
  186.  
  187.  
  188. exit_msg("Done. You may use the ProCalcTableUpdate Genie to update the table if values change.")
  189. break_d:
  190. break_e:
  191. break_c:
  192. halt:
  193.     call exit_msg("User aborted Genie!")
  194.  
  195. exit_msg: procedure expose units
  196. do
  197.     parse arg message
  198.  
  199.     call ppm_ClearStatus()
  200.     if message ~= '' then call ppm_Inform(1, message,)
  201.     call ppm_SetUnits(units)
  202.  
  203.         if show(p, "PCALC") then
  204.         do
  205.             address PCALC
  206.             'UnSuppress'
  207.             'UnLockGUI'
  208.         end
  209.  
  210.         call ppm_AutoUpdate(1)
  211.     exit
  212. end
  213.  
  214. cell_to_row:
  215. do
  216.     arg cell
  217.  
  218.     row = ''
  219.  
  220.     do i = 1 to length(cell)
  221.         char    = substr(cell,i, 1)
  222.         if datatype(char) = 'NUM' then
  223.             row = row || char
  224.     end
  225.     return row
  226. end
  227.  
  228.  
  229. cell_to_col:
  230. do
  231.     arg cell
  232.     numbers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  233.     col     = 0
  234.  
  235.     do i = 1 to length(cell)
  236.         char    = substr(cell,i, 1)
  237.         if datatype(char) = 'NUM' then leave
  238.         col     = col + ((26 ** (i - 1)) * pos(char, numbers))
  239.     end
  240.     return col
  241. end
  242.  
  243. fcomponent: procedure
  244. do
  245.     arg filename
  246.  
  247.     slash = max(lastpos('/', filename), lastpos(':', filename))
  248.  
  249.     if slash = 0 then return(filename)
  250.     else return(substr(filename, slash + 1))
  251. end
  252.